/********************************************************************

Replication Data for: "How Much is One American Worth? 
How Competition Affects Trade Preferences", APSR

Author: Diana C. Mutz, Hye-Yon Lee	
Date: May 2020

********************************************************************/

use "replication-data_trade_us_canada_merged.dta", clear


/* Fig 1, Table B1: Ethnocentric Valuation Test  */
anova tradesup country##EthnoVal Extent##EthnoVal c.tradeprefindex
margins country#EthnoVal, at((means) tradeprefindex)
 
marginsplot, by(country) title("") ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("") graphregion(color(white)) imargin(large)) plotregion(margin(small)) ///
subtitle(, lcolor(white) bcolor(none)) plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Gains" "Home Loses"' 1 `" "Partner Loses" "Home Gains"') 



/* Fig 2, Table B2: Moral Exclusion Test  */
anova tradesup country##MorExcl Extent##MorExcl c.tradeprefindex
margins country#MorExcl, at((means) tradeprefindex)  
 
marginsplot, by(country) title("") ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("") graphregion(color(white)) imargin(large)) plotregion(margin(small)) ///
subtitle(, lcolor(white) bcolor(none)) plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Loses" "Home Gains"' 1 `" "Partner Gains" "Home Gains"')



/* Fig 3, Table B3: SDO Moderates Ethnocentric Valuation  */ 

*By Country 
/* US */
anova tradesup i.EthnoVal##i.sdo01 i.Extent##i.EthnoVal c.tradeprefindex if country==0 
margins i.EthnoVal#i.sdo01, at((means) tradeprefindex) 
 
marginsplot, by(sdo01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("US", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Gains" "Home Loses"' 1 `" "Partner Loses" "Home Gains"') 

/* Canada */
anova tradesup i.EthnoVal##i.sdo01 i.Extent##i.EthnoVal c.tradeprefindex if country==1  
margins i.EthnoVal#i.sdo01, at((means) tradeprefindex) 

marginsplot, by(sdo01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("Canada", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Gains" "Home Loses"' 1 `" "Partner Loses" "Home Gains"') 


*Pooled 
anova tradesup i.EthnoVal##i.sdo01 i.Extent##i.EthnoVal c.tradeprefindex 

*Testing for three way interactions between treatment, SDO, and country
anova tradesup i.EthnoVal##i.sdo01##i.country i.Extent##i.EthnoVal c.tradeprefindex 



/* Fig 4, Table B4: SDO Moderates Moral Exclusion  */ 

*By Country 
/* US */
anova tradesup i.MorExcl##i.sdo01 i.Extent##i.MorExcl c.tradeprefindex if country==0 
margins i.MorExcl#i.sdo01, at((means) tradeprefindex) 
 
marginsplot, by(sdo01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("US", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Loses" "Home Gains"' 1 `" "Partner Gains" "Home Gains"')

/* Canada */
anova tradesup i.MorExcl##i.sdo01 i.Extent##i.MorExcl c.tradeprefindex if country==1  
margins i.MorExcl#i.sdo01, at((means) tradeprefindex) 

marginsplot, by(sdo01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("Canada", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Loses" "Home Gains"' 1 `" "Partner Gains" "Home Gains"')


*Pooled
anova tradesup i.MorExcl##i.sdo01 i.Extent##i.MorExcl c.tradeprefindex 

*Testing for three way interactions between treatment, SDO, and country
anova tradesup i.MorExcl##i.sdo01##i.country i.Extent##i.MorExcl c.tradeprefindex 



/* Fig 5, Table B5: Empathy Moderates Ethnocentric Valuation  */ 

*By Country 
/* US */
anova tradesup i.EthnoVal##i.empathy01 i.Extent##i.EthnoVal c.tradeprefindex if country==0 
margins i.EthnoVal#i.empathy01, at((means) tradeprefindex) 
 
marginsplot, by(empathy01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("US", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Gains" "Home Loses"' 1 `" "Partner Loses" "Home Gains"') 

/* Canada */
anova tradesup i.EthnoVal##i.empathy01 i.Extent##i.EthnoVal c.tradeprefindex if country==1  
margins i.EthnoVal#i.empathy01, at((means) tradeprefindex) 

marginsplot, by(empathy01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("Canada", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Gains" "Home Loses"' 1 `" "Partner Loses" "Home Gains"') 


*Pooled
anova tradesup i.EthnoVal##i.empathy01 i.Extent##i.EthnoVal c.tradeprefindex 

*Testing for three way interactions between treatment, empathy, and country
anova tradesup i.EthnoVal##i.empathy01##i.country i.Extent##i.EthnoVal c.tradeprefindex 



/* Fig 6, Table B6: Empathy Moderates Moral Exclusion  */ 

*By Country 
/* US */
anova tradesup i.MorExcl##i.empathy01 i.Extent##i.MorExcl c.tradeprefindex if country==0 
margins i.MorExcl#i.empathy01, at((means) tradeprefindex) 
 
marginsplot, by(empathy01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("US", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Loses" "Home Gains"' 1 `" "Partner Gains" "Home Gains"')

/* Canada */
anova tradesup i.MorExcl##i.empathy01 i.Extent##i.MorExcl c.tradeprefindex if country==1  
margins i.MorExcl#i.empathy01, at((means) tradeprefindex) 

marginsplot, by(empathy01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("Canada", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Loses" "Home Gains"' 1 `" "Partner Gains" "Home Gains"')


*Pooled
anova tradesup i.MorExcl##i.empathy01 i.Extent##i.MorExcl c.tradeprefindex 

*Testing for three way interactions between treatment, empathy, and country
anova tradesup i.MorExcl##i.empathy01##i.country i.Extent##i.MorExcl c.tradeprefindex 



/* Fig 7, Table B7: Zero Sum Perceptions Moderate Ethnocentric Valuation  */ 

*By Country 
/* US */
anova tradesup i.EthnoVal##i.zerosum01 i.Extent##i.EthnoVal c.tradeprefindex if country==0 
margins i.EthnoVal#i.zerosum01, at((means) tradeprefindex) 
 
marginsplot, by(zerosum01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("US", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Gains" "Home Loses"' 1 `" "Partner Loses" "Home Gains"') 

/* Canada */
anova tradesup i.EthnoVal##i.zerosum01 i.Extent##i.EthnoVal c.tradeprefindex if country==1  
margins i.EthnoVal#i.zerosum01, at((means) tradeprefindex) 

marginsplot, by(zerosum01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("Canada", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Gains" "Home Loses"' 1 `" "Partner Loses" "Home Gains"') 


*Pooled
anova tradesup i.EthnoVal##i.zerosum01 i.Extent##i.EthnoVal c.tradeprefindex 

*Testing for three way interactions between treatment, zero sum perceptions, and country
anova tradesup i.EthnoVal##i.zerosum01##i.country i.Extent##i.EthnoVal c.tradeprefindex 



/* Fig 8, Table B8: Zero Sum Perceptions Moderate Moral Exclusion  */ 

*By Country 
/* US */
anova tradesup i.MorExcl##i.zerosum01 i.Extent##i.MorExcl c.tradeprefindex if country==0 
margins i.MorExcl#i.zerosum01, at((means) tradeprefindex) 
 
marginsplot, by(zerosum01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("US", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Loses" "Home Gains"' 1 `" "Partner Gains" "Home Gains"')

/* Canada */
anova tradesup i.MorExcl##i.zerosum01 i.Extent##i.MorExcl c.tradeprefindex if country==1  
margins i.MorExcl#i.zerosum01, at((means) tradeprefindex) 

marginsplot, by(zerosum01) ytitle("") xtitle("") recast(bar) ///
ylabel(1 `""Strongly" "Oppose""' 2 " " 3 " " 4 `""Strongly" "Favor""', nogrid angle(h)) /// 
byopt(title("Canada", size(medsmall) yoffset(-5)) graphregion(color(white)) imargin(large)) ///
plotregion(margin(small)) subtitle(, yoffset(-15) lcolor(white) bcolor(none)) ///
plotopts(barw(.6) bcolor(gs5)) ciopts(lcolor(black)) /// 
xlabel(0 `" "Partner Loses" "Home Gains"' 1 `" "Partner Gains" "Home Gains"')


*Pooled
anova tradesup i.MorExcl##i.zerosum01 i.Extent##i.MorExcl c.tradeprefindex 

*Testing for three way interactions between treatment, zero sum perceptions, and country
anova tradesup i.MorExcl##i.zerosum01##i.country i.Extent##i.MorExcl c.tradeprefindex 



/* Fig 9: How Much is One Canadian or American Job Worth  */ 
egen MeanSup = mean(tradesup), by(Extent country EthnoVal)

/* Canada */
twoway (line MeanSup Extent if EthnoVal==0 & country==1, sort lcolor(black) lwidth(medthick) lpattern(dash)) ///
(line MeanSup Extent if EthnoVal==1 & country==1, sort lcolor(black) lwidth(medthick)), ///
ytitle("") yscale(noline) xline(3, lpattern(tight_dot) lcolor(black) noextend) /// 
ylabel(4(0.5)1, angle(horizontal) format(%8.1fc)valuelabel noticks glcolor(gs15) gmin gmax) ///
xtitle("") xlabel(1(1)7, valuelabel) title("") legend(off) ///
graphregion(margin(large) fcolor(white)) plotregion(margin(medium)) ///
text(3.2 6.3 "Trading Partner" "Loses / Canada Gains" ) ///
text(1.7 6.3 "Trading Partner" "Gains / Canada Loses" )

/* US */
twoway (line MeanSup Extent if EthnoVal==0 & country==0, sort lcolor(black) lwidth(medthick) lpattern(dash)) ///
(line MeanSup Extent if EthnoVal==1 & country==0, sort lcolor(black) lwidth(medthick)), ///
ytitle("") yscale(noline) /// 
ylabel(4(0.5)1, angle(horizontal) format(%8.1fc)valuelabel noticks glcolor(gs15) gmin gmax) ///
xtitle("") xlabel(1(1)7, valuelabel) title("") legend(off) ///
graphregion(margin(large) fcolor(white)) plotregion(margin(medium)) ///
text(3.5 6.3 "Trading Partner" "Loses / US Gains" ) ///
text(1.2 6.3 "Trading Partner" "Gains / US Loses" )



**************************************
////*** Supplemental Materials ***//// 
**************************************

/* Manipulation Checks (Appendix C) */ 
*Figure C1
anova usbenefitT i.EthnoVal if country==0
margins i.EthnoVal
anova tpcbenefitT i.EthnoVal if country==0
margins i.EthnoVal

*Figure C2
anova cabenefitT i.EthnoVal if country==1
margins i.EthnoVal
anova tpcbenefitT i.EthnoVal if country==1
margins i.EthnoVal

*Figure C3
anova tpcbenefitT i.MorExcl if country==0
margins i.MorExcl
anova tpcbenefitT i.MorExcl if country==1
margins i.MorExcl



/* Experimental Analysis Using Sampling Weights (Appendix H) */ 
svyset [pweight=weight]
recode country (1=0) (0=1), gen(us)

svy: reg tradesup us##EthnoVal Extent##EthnoVal c.tradeprefindex
svy: reg tradesup us##MorExcl Extent##MorExcl c.tradeprefindex
svy: reg tradesup i.EthnoVal##i.sdo01 i.Extent##i.EthnoVal c.tradeprefindex 
svy: reg tradesup i.MorExcl##i.sdo01 i.Extent##i.MorExcl c.tradeprefindex 
svy: reg tradesup i.EthnoVal##i.empathy01 i.Extent##i.EthnoVal c.tradeprefindex 
svy: reg tradesup i.MorExcl##i.empathy01 i.Extent##i.MorExcl c.tradeprefindex 
svy: reg tradesup i.EthnoVal##i.zerosum01 i.Extent##i.EthnoVal c.tradeprefindex 
svy: reg tradesup i.MorExcl##i.zerosum01 i.Extent##i.MorExcl c.tradeprefindex 




**************************************
/////*** Recoding  Variables  ***///// 
**************************************

/* US Data */

*pre-treatment trade preferences index: higher=more supportive
recode Q1 (1=4) (4=1) (2=3) (3=2) (else=.), gen(q1r)
recode Q2 (1=4) (4=1) (2=3) (3=2) (else=.), gen(q2r)
recode Q3 (1=4) (4=1) (2=3) (3=2) (else=.), gen(q3r)
recode Q4 (1=4) (4=1) (2=3) (3=2) (else=.), gen(q4r)
recode Q5 (1=4) (4=1) (2=3) (3=2) (else=.), gen(q5r)
alpha q1r q2r q3r q4r q5r 

egen Tvalid = rownonmiss(q1r q2r q3r q4r q5r) 
egen tradeprefindex = rmean(q1r q2r q3r q4r q5r) if Tvalid >= 3
sum tradeprefindex
label var tradeprefindex "Pre-Experiment Trade Index" 

*recoding experimental conditions 
gen conditions=W2_SURVEY_ASSIGN

gen Extent=. 
replace Extent = 4 if conditions==1 | conditions==5 | conditions==9 
replace Extent = 3 if conditions==2 | conditions==6 | conditions==10
replace Extent = 2 if conditions==3 | conditions==7 | conditions==11
replace Extent = 1 if conditions==4 | conditions==8 | conditions==12
replace Extent = 5 if conditions==16 | conditions==13 | conditions==19
replace Extent = 6 if conditions==17 | conditions==14 | conditions==20
replace Extent = 7 if conditions==18 | conditions==15 | conditions==21
label var Extent "Extent of Gain/Loss" 

gen Whogains=.
label define Whogains 1 "TPC gains/Home loses" 2 "TPC loses/Home gains" 3 "TPC gains/Home gains"
label values Whogains Whogains
replace Whogains = 1 if conditions==1 | conditions==2 | conditions==3 | conditions==4 | conditions==13 | conditions==14 | conditions==15
replace Whogains = 2 if conditions==5 | conditions==6 | conditions==7 | conditions==8 | conditions==16 | conditions==17 | conditions==18
replace Whogains = 3 if conditions==9 | conditions==10 | conditions==11 | conditions==12 | conditions==19 | conditions==20 | conditions==21
tab Whogains

*creating ethnocentric valuation test 
recode Whogains (1=0) (2=1) (else=.), gen(EthnoVal)
label define EthnoVal 0 "TPC gains/Home loses" 1 "TPC loses/Home gains"
label values EthnoVal EthnoVal

*creating moral exclusion test 
recode Whogains (2=0) (3=1) (else=.), gen(MorExcl)
label define MorExcl 0 "TPC loses/Home gains" 1 "TPC gains/Home gains"
label values MorExcl MorExcl
label var EthnoVal "Ethnocentric Valuation Test"
label var MorExcl "Moral Exclusion Test" 

*DV trade support: higher=more supportive
gen tradesup = . 
replace tradesup = 1 if W2_Q0==2 & W2_Q2==1
replace tradesup = 2 if W2_Q0==2 & W2_Q2==2
replace tradesup = 3 if W2_Q0==1 & W2_Q1==2
replace tradesup = 4 if W2_Q0==1 & W2_Q1==1
label var tradesup "Trade Support (1-4)" 

*computing sdo: higher = higher in sdo
recode W3_Q3_1 (-1=.)(1=10) (2=9) (3=8) (4=7) (5=6) (6=5) (7=4) (8=3) (9=2) (10=1), gen(w3_q3_1_v2)
recode W3_Q3_3 (-1=.)(1=10) (2=9) (3=8) (4=7) (5=6) (6=5) (7=4) (8=3) (9=2) (10=1), gen(w3_q3_3_v2)
recode W3_Q3_2 (-1=.)(1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7=7) (8=8) (9=9) (10=10), gen(w3_q3_2_v2)
recode W3_Q3_4 (-1=.)(1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7=7) (8=8) (9=9) (10=10), gen(w3_q3_4_v2)

alpha w3_q3_1_v2 w3_q3_2_v2 w3_q3_3_v2 w3_q3_4_v2

egen SDOvalid = rownonmiss(w3_q3_1_v2 w3_q3_2_v2 w3_q3_3_v2 w3_q3_4_v2) 
egen sdo = rmean(w3_q3_1_v2 w3_q3_2_v2 w3_q3_3_v2 w3_q3_4_v2) if SDOvalid >= 3

*computing empathy: higher = more empathetic
recode W3_q4_1 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(W3_q4_1_v2)
recode W3_q4_2 (1=5) (4=2) (3=3) (2=4) (5=1) (else=.), gen(W3_q4_2_v2)
recode W3_q4_3 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(W3_q4_3_v2)
recode W3_q4_4 (1=5) (4=2) (3=3) (2=4) (5=1) (else=.), gen(W3_q4_4_v2)
recode W3_q4_5 (1=5) (4=2) (3=3) (2=4) (5=1) (else=.), gen(W3_q4_5_v2)
recode W3_q4_6 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(W3_q4_6_v2)
recode W3_q4_7 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(W3_q4_7_v2)

alpha W3_q4_1_v2-W3_q4_7_v2 

egen EMvalid = rownonmiss(W3_q4_1_v2-W3_q4_7_v2 ) 
egen empathy = rmean(W3_q4_1_v2-W3_q4_7_v2) if EMvalid >= 3

*computing zero sum perceptions
recode Q6M (1=5) (5=1) (2=4) (4=2) (3=3), gen(q6mR)
recode q6mR (1 2 =1) (3=2) (4 5=3), gen(q6mT)
recode Q7M (1=5) (5=1) (2=4) (4=2) (3=3), gen(q7mR)
recode q7mR (1 2 =1) (3=2) (4 5=3), gen(q7mT)
label var q6mR "US job availability"
label var q7mR "TPC job availability"

gen zerosum01=0
replace zerosum01=1 if q6mT==1 & q7mT==3
tab zerosum01
label define zerosum01 0"No Zero Sum" 1"Zero Sum Perceptions" 
label values zerosum01 zerosum01

***creating variables for the manipulation checks: 3=HOME BENEFITS MORE, 2=SAME, 1=TPC BENEFITS MORE
gen usbenefitT= . 
replace usbenefitT= 2 if  W2_Q6==1 & W2_Q8==1
replace usbenefitT= 1 if  W2_Q6==1 & W2_Q8==2
replace usbenefitT= 0 if  W2_Q6==2
replace usbenefitT= 0 if  W2_Q6==3 & W2_Q7==2
replace usbenefitT= 0 if  W2_Q6==3 & W2_Q7==1

gen tpcbenefitT = . 
replace tpcbenefitT= 0 if W2_Q6==1 & W2_Q8==1 
replace tpcbenefitT= 0 if W2_Q6==1 & W2_Q8==2 
replace tpcbenefitT= 0 if W2_Q6==2
replace tpcbenefitT= 1 if W2_Q6==3 & W2_Q7==2 
replace tpcbenefitT= 2 if W2_Q6==3 & W2_Q7==1 

save "USData.dta"


/* CANADA Data */

*pre-treatment trade preferences index
egen tradeprefindex=rowmean(Q1 Q2 Q3 Q4 Q5)
replace tradeprefindex=5-tradeprefindex

*recoding experimental conditions 
gen conditions=DOV_SURVEY_ASSIGN
gen Extent=. 
replace Extent = 4 if conditions==1 | conditions==5 | conditions==9 
replace Extent = 3 if conditions==2 | conditions==6 | conditions==10
replace Extent = 2 if conditions==3 | conditions==7 | conditions==11
replace Extent = 1 if conditions==4 | conditions==8 | conditions==12
replace Extent = 5 if conditions==16 | conditions==13 | conditions==19
replace Extent = 6 if conditions==17 | conditions==14 | conditions==20
replace Extent = 7 if conditions==18 | conditions==15 | conditions==21
label var Extent "Extent of Gain/Loss" 

gen Whogains=.
label define Whogains 1 "TPC gains/Home loses" 2 "TPC loses/Home gains" 3 "TPC gains/Home gains", replace
label values Whogains Whogains
replace Whogains = 1 if conditions==1 | conditions==2 | conditions==3 | conditions==4 | conditions==13 | conditions==14 | conditions==15
replace Whogains = 2 if conditions==5 | conditions==6 | conditions==7 | conditions==8 | conditions==16 | conditions==17 | conditions==18
replace Whogains = 3 if conditions==9 | conditions==10 | conditions==11 | conditions==12 | conditions==19 | conditions==20 | conditions==21
tab Whogains

*creating ethnocentric valuation test 
recode Whogains (1=0) (2=1) (else=.), gen(EthnoVal)
label define EthnoVal 0 "TPC gains/Home loses" 1 "TPC loses/Home gains"
label values EthnoVal EthnoVal

*creating moral exclusion test 
recode Whogains (2=0) (3=1) (else=.), gen(MorExcl)
label define MorExcl 0 "TPC loses/Home gains" 1 "TPC gains/Home gains"
label values MorExcl MorExcl
label var EthnoVal "Ethnocentric Valuation Test"
label var MorExcl "Moral Exclusion Test" 

*DV trade support: higher=more supportive
gen tradesup = . 
replace tradesup = 4 if S3_0==1 & S3_1==1
replace tradesup = 3 if S3_0==1 & S3_1==2
replace tradesup = 1 if S3_0==2 & S3_2==1
replace tradesup = 2 if S3_0==2 & S3_2==2
label var tradesup "Trade Support (1-4)" 

*computing sdo: higher = higher in sdo
recode Q15_1 (1=10) (2=9) (3=8) (4=7) (5=6) (6=5) (7=4) (8=3) (9=2) (10=1), gen(w3_q3_1_v2)
recode Q15_3 (1=10) (2=9) (3=8) (4=7) (5=6) (6=5) (7=4) (8=3) (9=2) (10=1), gen(w3_q3_3_v2)
recode Q15_2 (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7=7) (8=8) (9=9) (10=10), gen(w3_q3_2_v2)
recode Q15_4 (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7=7) (8=8) (9=9) (10=10), gen(w3_q3_4_v2)

alpha w3_q3_1_v2 w3_q3_3_v2 w3_q3_2_v2 w3_q3_4_v2

egen SDOvalid = rownonmiss(w3_q3_1_v2 w3_q3_3_v2 w3_q3_2_v2 w3_q3_4_v2) 
egen sdo = rmean(w3_q3_1_v2 w3_q3_2_v2 w3_q3_3_v2 w3_q3_4_v2) if SDOvalid >= 3

*computing empathy: higher = more empathetic
recode Q16_1 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(emp1)
recode Q16_2 (1=5) (4=2) (3=3) (2=4) (5=1) (else=.), gen(emp2)
recode Q16_3 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(emp3)
recode Q16_4 (1=5) (4=2) (3=3) (2=4) (5=1) (else=.), gen(emp4)
recode Q16_5 (1=5) (4=2) (3=3) (2=4) (5=1) (else=.), gen(emp5)
recode Q16_6 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(emp6)
recode Q16_7 (1=1) (2=2) (3=3) (4=4) (5=5) (else=.), gen(emp7)

alpha emp1 emp2 emp3 emp4 emp5 emp6 emp7
egen empathy = rmean(emp1 emp2 emp3 emp4 emp5 emp6 emp7) 

*computing zero sum perceptions
recode Q6M (1=5) (5=1) (2=4) (4=2) (3=3), gen(q6mR)
recode q6mR (1 2 =1) (3=2) (4 5=3), gen(q6mT)
recode Q7M (1=5) (5=1) (2=4) (4=2) (3=3), gen(q7mR)
recode q7mR (1 2 =1) (3=2) (4 5=3), gen(q7mT)
label var q6mR "Home job availability"
label var q7mR "TPC job availability"

gen zerosum01=0
replace zerosum01=1 if q6mT==1 & q7mT==3
tab zerosum01
label define zerosum01 0"No Zero Sum" 1"Zero Sum Perceptions" 
label values zerosum01 zerosum01

***creating variables for the manipulation checks: 3=HOME BENEFITS MORE, 2=SAME, 1=TPC BENEFITS MORE
gen cabenefitT= . 
replace cabenefitT= 2 if  S3_6==1 & S3_8==1
replace cabenefitT= 1 if  S3_6==1 & S3_8==2
replace cabenefitT= 0 if  S3_6==2
replace cabenefitT= 0 if  S3_6==3 & S3_7==2
replace cabenefitT= 0 if  S3_6==3 & S3_7==1

gen tpcbenefitT = . 
replace tpcbenefitT= 0 if S3_6==1 & S3_8==1
replace tpcbenefitT= 0 if S3_6==1 & S3_8==2
replace tpcbenefitT= 0 if S3_6==2 
replace tpcbenefitT= 1 if S3_6==3 & S3_7==2
replace tpcbenefitT= 2 if S3_6==3 & S3_7==1

save "CanadaData.dta"


/* Merging US and CANADA Data */

use "USData.dta"
append using "CanadaData.dta", generate(country)
label define country 0"US" 1"Canada" 
label values country country
order weight country tradeprefindex conditions Extent Whogains EthnoVal MorExcl tradesup sdo empathy zerosum01 usbenefitT tpcbenefitT cabenefitT, after(CaseID)

sum sdo, detail
gen byte sdo01 = cond(missing(sdo), ., (sdo >= r(p50)))
sum sdo01 
label var sdo01 "SDO (0-1)"

sum empathy, detail
gen byte empathy01 = cond(missing(empathy), ., (empathy >= r(p50)))
sum empathy01
label var empathy01 "Empathy (0-1)" 

order sdo01 empathy01, before(zerosum01)

save "replication-data_trade_us_canada_merged.dta" 






